package com.eliza.base.animation

import android.annotation.SuppressLint
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.test.captureToImage
import androidx.compose.ui.unit.dp
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.tooling.preview.Preview
import org.junit.Rule
import org.junit.Test

class AnimationTestingSnippets {

    @get:Rule
    val rule = createComposeRule()

    @Composable
    @Test
    fun testAnimationWithClock() {
        // Pause animations
        rule.mainClock.autoAdvance = false
        var enabled by remember {
            mutableStateOf(false)
        }
        rule.setContent {
            val color by animateColorAsState(
                targetValue = if (enabled) Color.Red else Color.Green,
                animationSpec = tween(durationMillis = 250), label = ""
            )
            Box(
                modifier = Modifier
                    .size(64.dp)
                    .background(color)
            )
        }

        // Initiate the animation.
        enabled = true

        // Let the animation proceed.
        rule.mainClock.advanceTimeBy(50L)

        // Compare the result with the image showing the expected result.
        // `assertAgainGolden` needs to be implemented in your code.
        rule.onRoot().captureToImage().assertAgainstGolden()
    }

    private fun ImageBitmap.assertAgainstGolden() {
    }
}

@Preview
@Composable
private fun Show() {
    asd.ass()
}

object asd {
    @Composable
    fun ass() {
        Text(text = "asssas")
    }
}
